Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

320
Visualizações
how is [1,2,3]==[1,2,3] false in javascript?

how is [1,2,3]==[1,2,3] and [1,2,3]===[1,2,3] false? Would appreciate a simple explanation. Came across this while watching a youtube video.. anymore "anomalies" like this?

about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

The == operator checks whether the two operands reference the same object. While the two objects (arrays are objects) may have the same content, they are different instances, and thus the expression is false.

about 4 years ago · Juan Pablo Isaza Relatório

0

The === and == operators compares arrays by reference (i.e. location in memory), the easy way to think about it is that "they are different arrays with the same values".

If you give you arrays a name, maybe the reason for this will be clearer:

const arr1 = [1, 2, 3];
const arr2 = [1, 2, 3];

console.log(arr1 === arr2);

And arr1 is not the same array as arr2.

Conversely, this will log true, because it compares the same reference:

const arr = [1, 2, 3];

console.log(arr === arr);
about 4 years ago · Juan Pablo Isaza Relatório

0

They are not equal because they are not the "same". In js, if you do [1,2,3] it stores the array as a variable with no name. Give it a name, say 'r', and do r==r and it will return true because window.r is the same as window.r. But window.undefinedvariable0 is not the same as window.undefinedvariable1, although they are visually the same.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda